package cn.lf.android.lawfirm.inputsource.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import cn.lf.android.lawfirm.R;
import cn.lf.android.lawfirm.inputsource.model.QuasiCommissionedPartyEntity;
import cn.lf.android.lawfirm.utils.DebugLog;

/**
 * 拟委托方适配器
 */
public class QuasiCommissionedPartyAdapter extends BaseAdapter {

    Context context;
    List<QuasiCommissionedPartyEntity> list;
    private LayoutInflater inflater;

    public QuasiCommissionedPartyAdapter(Context context, List<QuasiCommissionedPartyEntity> list) {
        super();
        this.context = context;
        this.list = list;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            viewHolder = new ViewHolder();
            convertView = inflater.inflate(R.layout.item_quasicommissionedparty_new, null);
            viewHolder.name = (TextView) convertView.findViewById(R.id.name);
            viewHolder.tell = (TextView) convertView.findViewById(R.id.tell);
            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        DebugLog.e("------" + list.get(position).getName());
        viewHolder.name.setText(list.get(position).getName());
        if (null == list.get(position).getLinkmen() || list.get(position).getLinkmen().length() == 0) {
            viewHolder.tell.setText("");
            viewHolder.tell.setVisibility(View.GONE);
        } else {
            viewHolder.tell.setText(list.get(position).getLinkmen() + "  " + list.get(position).getLinkTel());
            viewHolder.tell.setVisibility(View.VISIBLE);
        }

        return convertView;
    }

    class ViewHolder {
        TextView name, tell;
    }
}
